<include file="Public:header" />
<script type="text/javascript">

function doCommand(command)
{
    var sql = $("#sql").val();
    if (sql == '') {
        alert('SQL不能为空');
        return false;
    }
    $.ajax({
        type: "POST",
        url: '{:U("Database/doQuery")}',
        data: {
            runSql: sql
        },
        beforeSend: function() {
            $("#msg").html('<span style="color:#FF0000"><img src="__PUBLIC__/Admin/loading.gif" align="absmiddle">正在提交...</span>');
        },
        success: function(data) {
            switch (data) {
            case 'errorVerifyCode':
                break
            default:
                $("#msg").html(data);
                $('#msg').show();
                //alert ('未知错误，请联系管理员');
            }

        }
    });
}

function checkUpload(){
		var file=$("input[name='sqlFile']").val()
		var filename=file.replace(/.*(\/|\\)/, "");
		var fileExt=(/[.]/.exec(filename)) ? /[^.]+$/.exec(filename.toLowerCase()) : '';
		if(filename == '')
		{
			alert('请选择要导入的SQL文件');
			return false;
		}
		
		
	}
</script>
<div class="mainarea">
<div class="maininner">
<div class="block style4">
		
		<table cellspacing="3" cellpadding="3">
		<tr>
		 <th style="width:50px; text-align:center"><a href="http://www.sgcms.cn/manual.php?app=shuguangCorp&module={$moduleName}" target="_blank"><img src="__PUBLIC__/Admin/help_1.gif" alt="" align="absmiddle" /><br />
帮助</a></th>
		  <td>1.请输入SQL语句，可同时执行多条语句，每行一条<br />
		    2.SQL执行后影响到的结果不可恢复，请谨慎使用此功能<br />
		    3.若数有重要数据，请在执行SQL语句前备份数据库，以免数据丢失</td>
		  </tr>
		</table>
	</div>

	<form method="post" action="{:U("Database/doQuery")}">
	
	<div class="body_content">
		
	 <div class="top_action"><a href="{:U("Database/index")}">返回管理</a> | <a href="{:U("Database/export")}">备份数据库</a> | <a href="{:U("Database/import")}">恢复数据库</a></div>
		
		<table cellspacing="0" cellpadding="0" id="maintable" class="formtable">
		<tr>
		  <th style="width:7em;">SQL语句</th>
		<td><textarea name="sql"  id="sql" style="width:94%; height:300px">SELECT * FROM sgcorp_config LIMIT 0,30</textarea></td></tr>
		<tr>
		  <th colspan="2"></th>
		  </tr>

		</tbody>
		
		</table>
	</div>
	
	
    <div class="foot_action">
		<input type="button" name="submit" value="执行SQL" class="submit" onclick="doCommand('exe')">
        <input type="reset" name="button" id="button" value="还原重填" class="submit"/>
        <div id="msg" style="display:none; margin-top:20px; clear:both;overflow-x:auto;"></div>
	</div>
	
	</form>
    <div class="body_content">
   <form action="{:U("Database/doUploadImport")}" method="post" enctype="multipart/form-data" name="upload" id="upload" onsubmit="return checkUpload()">
        <table  border="0" cellspacing="0" cellpadding="0" >
          <tr>
            <td rowspan="3">&nbsp;本地文件 </td>
            <td>
              <input type="file" name="sqlFile" id="sqlFile" />
              
                <input type="submit" name="button" id="button" value="提交操作" />
              </td>
          </tr>
          <tr>
            <td><span style="color:#F00">{$uploadTips}</span></td>
          </tr>
          <tr>
            <td>本地文件编码必须为UTF-8，否则会执行失败，支持本系统导出的.sql及phpmyadmin导出的标准格式</td>
          </tr>
        </table>
      </form>
    </div>
</div>
</div>

<div class="side">
<include file="Public:sider" />
</div>
<include file="Public:footer" />